<?php


namespace app\shop\controller\group;


use app\BaseController;
use app\shop\service\order\OrderService;

class SubOrderController extends BaseController
{
    /**
     * 创建子订单
     * @return \think\response\Json
     */
    public function createSubOrder()
    {
        try {
            $orderService = new OrderService();
            $orderService->createSubOrder($this->request);
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 获取子订单信息
     * @return \think\response\Json
     */
    public function getSubOrderDetail()
    {
        try {
            $userInfo = $this->request->middleware('userInfo');
            $subOrderId = $this->request->param('sub_order_id', 0, 'int');
            $orderService = new OrderService();
            $list = $orderService->getSubOrderDetail($subOrderId);
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 获取子订单信息
     * @return \think\response\Json
     */
    public function getSubOrderList()
    {
        try {
            $orderId = $this->request->param('order_id', 0, 'int');
            $orderService = new OrderService();
            $list = $orderService->getSubOrderList($orderId);
            return $this->success($list);
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }

    /**
     * 设置子订单状态
     * @return \think\response\Json
     */
    public function setSubOrderStatus()
    {
        try {
            $subOrderId = $this->request->param('sub_order_id', 0, 'int');
            $status = $this->request->param('status', 0, 'int');
            $orderService = new OrderService();
            $orderService->setSubOrderStatus($subOrderId, $status);
            return $this->success();
        } catch (\Exception $exception) {
            return $this->error($exception->getMessage());
        }
    }
}